<template>
  <div>
    <my-loading v-if="isShow"></my-loading>
    <div id="content" v-else>
      <div class="cinema_menu">
        <div class="city_switch">
          全城
          <i class="iconfont icon-lower-triangle"></i>
        </div>
        <div class="brand_swtich">
          品牌
          <i class="iconfont icon-lower-triangle"></i>
        </div>
        <div class="feature_switch">
          特色
          <i class="iconfont icon-lower-triangle"></i>
        </div>
      </div>
      <div class="cinema_body">
        <ul>
          <li v-for="(item) in cinemaList" :key="item.id">
            <div>
              <span>{{item.nm}}</span>
              <span class="q">
                <span class="price">{{item.sellPrice}}</span> 元起
              </span>
            </div>
            <div class="address">
              <span>{{item.addr}}</span>
              <span>{{item.distance}}</span>
            </div>
            <div class="card">
              <div v-for="(value, key) in item.tag" :key="key" v-if="value===1" :class="key | formatColor">{{key | formatCard}}</div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      cinemaList: [],
      checkId:-1,
      isShow:true
    }
  },
  methods: {
    async getCinemaList() {
      let res = await this.$axios.get(`/api/cinemaList?cityId=${this.$store.state.city.id}`)
      if (res.msg !== 'ok') {
        console.log('获取影院信息失败')
        return
      }
      this.checkId = this.$store.state.city.id
      this.cinemaList = res.data.cinemas
      console.log(this.cinemaList);
      this.isShow = false;
    }
  },
  activated() {
    if(this.checkId === this.$store.state.city.id)return;
    console.log(3);
    
    this.getCinemaList()
  },
  filters: {
    formatCard(key) {
      var cards = [
        { key: 'allowRefund', value: '退票' },
        { key: 'buyout', value: '售空' },
        { key: 'endorse', value: '推荐' },
        { key: 'sell', value: '折扣卡' },
        { key: 'snack', value: '小吃' },
        { key: 'deal', value: '预售' }
      ]
      for(let i=0;i<cards.length;i++){
        if(key===cards[i].key){
          return cards[i].value
        }
        
      }
      return 
    },
    formatColor(key){
        var cards = [
        { key: 'allowRefund', value: 'or' },
        { key: 'buyout', value: 'or' },
        { key: 'endorse', value: 'bl' },
        { key: 'sell', value: 'bl' },
        { key: 'snack', value: 'bl' },
        { key: 'deal', value: 'bl' }
      ]
      for(let i=0;i<cards.length;i++){
        if(key===cards[i].key){
          return cards[i].value
        }
        
      }
      return 
    }
  }
}
</script>
<style scoped>
#content .cinema_menu {
  width: 100%;
  height: 45px;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: white;
  position: fixed;
  top: 50px;
}
#content .cinema_body {
  flex: 1;
  overflow: auto;
  padding-top: 92px;
}
.cinema_body ul {
  padding: 20px;
}
.cinema_body li {
  border-bottom: 1px solid #e6e6e6;
  margin-bottom: 20px;
}
.cinema_body div {
  margin-bottom: 10px;
}
.cinema_body .q {
  font-size: 11px;
  color: #f03d37;
}
.cinema_body .price {
  font-size: 18px;
}
.cinema_body .address {
  font-size: 13px;
  color: #666;
}
.cinema_body .address span:nth-of-type(2) {
  float: right;
}
.cinema_body .card {
  display: flex;
}
.cinema_body .card div {
  padding: 0 3px;
  height: 15px;
  line-height: 15px;
  border-radius: 2px;
  color: #f90;
  border: 1px solid #f90;
  font-size: 13px;
  margin-right: 5px;
}
.cinema_body .card div.or {
  color: #f90;
  border: 1px solid #f90;
}
.cinema_body .card div.bl {
  color: #589daf;
  border: 1px solid #589daf;
}
</style>